#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File    :   dig_script.py    
@Contact :   291622538@qq.com

@Modify Time      @Author    @Version    @Description
------------      -------    --------    -----------
2021/3/31 15:23   fan        1.0         None
"""
from concurrent.futures import ThreadPoolExecutor
import time
import os


def say_hello(a):
    print("hello: " + a)
    time.sleep(2)


def dig_cmd(domain_name):
    cmd = "dig @1.1.1.1 +short $domain MX"
    f = os.popen(cmd)
    for num, line in enumerate(f):
        print(num, line)


if __name__ == '__main__':
    seed = ["a", "b", "c"]
    start2 = time.time()
    with ThreadPoolExecutor(3) as executor:
        for each in seed:
            executor.submit(say_hello, each)
    end2 = time.time()
    print("time2: " + str(end2 - start2))

    # start3 = time.time()
    # with ThreadPoolExecutor(3) as executor1:
    #     executor1.map(say_hello, seed)
    # end3 = time.time()
    # print("time3: " + str(end3 - start3))

    # domain_name_list = ["facebook.com", "google.com"]
    # start3 = time.time()
    # with ThreadPoolExecutor(3) as executor1:
    #     executor1.map(dig_cmd, domain_name_list)
    # end3 = time.time()
    # print("time3: " + str(end3 - start3))
